import 'package:get/get.dart';

import '../../../../generated/AlphaResponse.pb.dart';
import '../../../../generated/GetRobotConfiguration.pb.dart';
import '../../../logger/Logger.dart';
import '../../../robot_comm/cmd_const.dart';
import '../../../robot_comm/mqtt_comm_manager.dart';

class AboutRobotController extends GetxController {

   var robotResponse = GetRobotConfigurationResponse().obs;

   @override
  void onInit() {
    super.onInit();
    print('AboutRobotController -robotUserId---> ${Get.parameters['robotUserId']}');
  }

  @override
  void onReady() {
    super.onReady();
    robotConfigData();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void robotConfigData() {
    GetRobotConfigurationRequest request = GetRobotConfigurationRequest();
    MqttCommManager().sendCmd(CmdConst.IM_GET_ROBOT_CONFIG_REQUEST, request, (AlphaResponse msg){
      robotResponse.value = GetRobotConfigurationResponse.fromBuffer(msg.bodyData);
      robotResponse.value.mainappversion = maskMainAppVersion(robotResponse.value.mainappversion);
      logger.info("机器人配置信息： ${robotResponse.value}");

    });

  }

   String maskMainAppVersion(String mainAppVersion) {
     // 检查手机号长度是否合法（假设为11位）
     if (mainAppVersion.length > 13) {
       return "${mainAppVersion.substring(0, 13)}****";
     }
     return mainAppVersion;

   }

}
